import time
import random
import logging
from sniffylib.util import threads
import core

logger = logging.getLogger(__name__)

def random_position():
    position = tuple([random.randint(0, 100) for i in range(2)])
    return position


class RandomPositionService(core.BaseLocationService):
    
    def __init__(self, delay):
        core.BaseLocationService.__init__(self)
        self.position_handler = None
        self.service = threads.BgService(self.update_position, delay)        
    
    def start_service(self):
        self.service.start()
        
    def update_position(self):
        pos = random_position()
        if self.position_handler:
            self.position_handler.handle_position(pos)

    def stop_service(self):
        if self.service is not None and self.service.state:
            self.service.stop()
